﻿// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
using Newtonsoft.Json;

namespace ImageGallery.Store.Cosmos
{
    /// <summary>
    /// This class represents a Cosmos DB entity.
    /// </summary>
    public abstract class CosmosEntity
    {
        /// <summary>
        /// Gets the partition key.
        /// </summary>
        [JsonIgnore]
        public abstract string PartitionKey { get; }

        /// <summary>
        /// Gets or sets the unique identifier.
        /// </summary>
        [JsonProperty(PropertyName = "id")]
        public string Id { get; set; }

        /// <summary>
        /// Gets or sets the creation time.
        /// </summary>
        [JsonProperty(PropertyName = "createdTime")]
        public DateTime? CreatedTime { get; set; }

        /// <summary>
        /// Gets or sets the changed time.
        /// </summary>
        [JsonProperty(PropertyName = "changedTime")]
        public DateTime? ChangedTime { get; set; }

        /// <summary>
        /// Gets or sets the ETAG value used by CosmosDb to implement optimistic concurrency.
        /// </summary>
        [JsonProperty(PropertyName = "_etag", NullValueHandling = NullValueHandling.Ignore)]
        public string EntityTag { get; set; }

        /// <summary>
        /// Gets or sets the timestamp value generated by CosmosDb to implement ordering.
        /// </summary>
        [JsonProperty(PropertyName = "_ts")]
        public long CosmosDbTimeStamp { get; set; }

        /// <summary>
        /// Gets or sets the Time to Live (TTL). When time since last modification of the
        /// entity the value set here, the entity will be removed by Cosmos DB. This property
        /// will not have any effect if TTL is not enabled on the Cosmos DB container/collection.
        /// </summary>
        [JsonProperty(Required = Required.Default, DefaultValueHandling = DefaultValueHandling.Ignore, PropertyName = "ttl")]
        public int? TimeToLive { get; set; }
    }
}
